<%@ page language="java" import="java.util.*"
	contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<!DOCTYPE html>
<html>
<head>
<title>菜单信息录入</title>
<t:base type="jquery,easyui,tools"></t:base>
<script type="text/javascript">
  $(function() {
    $('#fatherName').combotree({
      url : 'wxMenuController.do?treeMenu&showChildren=false',
    });

    function refreshByType(type) {
      var urlDisabled = true, keyDisabled = false, mediaDisabled = true;

      if ('view' == type) {
        urlDisabled = false;
        keyDisabled = true;
      } else if ('media_id' == type || 'view_limited' == type) {
        keyDisabled = true;
        mediaDisabled = false;
      }

      if (urlDisabled) {
        $("#url").attr("disabled", "disabled");
        $("#url").removeAttr("datatype");
        $("#url").val("");
      } else {
        $("#url").removeAttr("disabled");
        $("#url").attr("datatype", "*");
      }

      if (keyDisabled) {
        $("#key").attr("disabled", "disabled");
        $("#key").removeAttr("datatype");
        $("#key").val("");
      } else {
        $("#key").removeAttr("disabled");
        $("#key").attr("datatype", "*");
      }

      if (mediaDisabled) {
        $("#media").attr("disabled", "disabled");
        $("#media").removeAttr("datatype");
        $("#media").val("");
      } else {
        $("#media").removeAttr("disabled");
        $("#media").attr("datatype", "*");
      }
    }

    $("#type").change(function() {
      var v = $(this).children('option:selected').val();
      refreshByType(v);
    });

    /* $("#type").change(function() {
      var selectValue = $(this).children('option:selected').val();
      if ("click" == selectValue) {
        $("#url").attr("disabled", "disabled");
        $("#trurl").attr("style", "display:none");

        $("#xxtr").removeAttr("style");
        var inputAttr = $("input[name='msgType']");
        for (var i = 0; i < inputAttr.length; i++) {
          $(inputAttr[i]).removeAttr("disabled");
          $(inputAttr[i]).attr("datatype", "*");
        }

        $("#templateTr").removeAttr("style");
        $("#templateId").removeAttr("disabled");

        //设置消息类型和验证
        $("#msgType").attr("datatype", "*");
        $("#templateId").attr("datatype", "*");
      } else {
        $("#url").removeAttr("disabled");
        $("#trurl").removeAttr("style");

        $("#xxtr").attr("style", "display:none");
        var inputAttr = $("input[name='msgType']");
        for (var i = 0; i < inputAttr.length; i++) {
          $(inputAttr[i]).attr("disabled", "disabled");
          $(inputAttr[i]).removeAttr("datatype");
        }

        $("#templateTr").attr("style", "display:none");
        $("#templateId").attr("disabled", "disabled");
        //取消验证。防止无法提交
        $("#msgType").removeAttr("datatype");
        $("#templateId").removeAttr("datatype");
      }
    }); */

    var fid = "${fatherId}";
    var msgType = "${msgType}";
    var type = "${type}";
    var templateId = "${templateId}";
    //var supMenuId="${fatherName}";

    var inputAttr = $("input[name='msgType']");
    for (var i = 0; i < inputAttr.length; i++) {
      $(inputAttr[i]).click(function() {
        var textVal = $(this).val();
        if ("text" == textVal) {
          getTemplates("text");
        } else if ("expand" == textVal) {
          getTemplates("expand");
        } else if ("news" == textVal) {
          getTemplates("news");
        }
      });
    }

    //获取动作设置选中的项,用于初始化依赖dom元素
    var typeVal = $("#type").val(); // 动作设置选中项的值
    refreshByType(typeVal);

    /* if ("click" == typeVal) {
      $("#xxtr").show();
      $("#trurl").hide();
      $("#templateTr").show();
      //设置消息类型和验证
      $("#msgType").attr("datatype", "*");
      $("#templateId").attr("datatype", "*");
    } else if ("view" == typeVal) {
      $("#xxtr").hide();
      $("#trurl").show();
      $("#templateTr").hide();
      $("#msgType").removeAttr("datatype");
      $("#templateId").removeAttr("datatype");
    }

    if (typeof (fatherId) == "undefined") {
      $("#msgType").removeAttr("datatype");
      $("#templateId").removeAttr("datatype");
    } */

  });

  function btnSubmit() {
    /*  var state = $('#state').val();
     if (state == 'no') {
         alert('二级菜单不能再扩展');
         return false;
     } */
  }
</script>
</head>
<body style="overflow-y: hidden" scroll="no">
	<t:formvalid formid="formobj" dialog="true" usePlugin="password"
		layout="table" action="wxMenuController.do?save"
		beforeSubmit="btnSubmit">
		<input id="state" name="state" type="hidden">
		<c:if test="${menuEntity.id!=null}">
			<input id="id" name="id" type="hidden" value="${menuEntity.id}">
		</c:if>
		<c:if test="${fatherId!=null}">
			<input id="fatherId" name="fatherId" type="hidden"
				value="${fatherId}">
		</c:if>
		<c:if test="${accountid!=null}">
			<input id="accountid" name="accountid" type="hidden"
				value="${accountid}">
		</c:if>
		<table style="width: 100%" cellpadding="0" cellspacing="1"
			class="formtable">
			<tr>
				<td align="right" style="width: 65px"><label
					class="Validform_label"> 菜单名称: </label></td>
				<td colspan="3" class="value"><input id="name" class="inputxt"
					name="name" value="${name}" datatype="*" nullmsg="菜单名称不能为空！">
					<span class="Validform_checktip">请输入 菜单名称！</span></td>
			</tr>

			<tr>
				<td align="right" style="width: 65px"><label
					class="Validform_label"> 上级菜单: </label></td>
				<td colspan="3" class="value"><input id="fatherName"
					name="fatherName" value="${fatherId}" /> <span
					class="Validform_checktip">请选择上级菜单！</span></td>
			</tr>

			<tr>
				<td align="right" style="width: 65px"><label
					class="Validform_label"> 类型: </label></td>
				<td colspan="3" class="value"><t:dictSelect field="type"
						id="type" type="list" typeGroupCode="wxmenutype"
						defaultVal="${type}" hasLabel="false" title="请设置动作"></t:dictSelect>
					<span class="Validform_checktip">请设置动作</span></td>
			</tr>

			<tr id="trurl">
				<td align="right" style="width: 65px"><label
					class="Validform_label"> URL: </label></td>
				<td colspan="3" class="value"><input id="url" class="inputxt"
					name="url" value="${url}" style="width: 300px"> <span
					class="Validform_checktip">填写url，格式需要以http开头，支持占位符:
						<table>
							<tr>
								<td>变量名称</td>
								<td>说明</td>
								<td>类型</td>
							</tr>
							<tr>
								<td>org</td>
								<td>TSDepart</td>
								<td>当前组织</td>
							</tr>
							<tr>
								<td>user</td>
								<td>TSUser</td>
								<td>当前人员</td>
							</tr>
							<tr>
								<td>wxaccount</td>
								<td>WxAccountEntity</td>
								<td>当前微信公众号</td>
							</tr>
							<tr>
								<td>wxpublicid</td>
								<td>String</td>
								<td>当前微信公众号原始id</td>
							</tr>
							<tr>
								<td>domain</td>
								<td>String</td>
								<td>当前域名</td>
							</tr>
						</table>
				</span> <br>示例:
					\${domain}/wxAccountController.do?user=\${user.id}&org=\${org.id}，最终生成的链接类似:
					http://www.gomoretech.com/wxAccountController.do?user=1234&org=5678
				</td>
			</tr>

			<tr>
				<td align="right" style="width: 65px"><label
					class="Validform_label"> 菜单关键字: </label></td>
				<td class="value" colspan="3"><input id="key" class="inputxt"
					name="menuKey" value="${menuKey}" nullmsg="菜单关键字不能为空！"> <span
					class="Validform_checktip">填写菜单关键字，系统会根据该关键字触发对应的动作，请参考<a
						href="wxAutoResponseController.do?list">关键字管理</a></span></td>
			</tr>

			<%-- 	<tr>
				<td align="right" style="width: 65px"><label
					class="Validform_label"> 素材: </label></td>
				<td class="value" colspan="3"><input id="media" class="inputxt"
					name="menuKey" value="${mediaId}" nullmsg="素材不能为空！"> <span
					class="Validform_checktip">请选择素材</span></td>
			</tr> --%>

			<tr>
				<td align="right" style="width: 65px"><label
					class="Validform_label"> 顺序: </label></td>
				<td class="value" colspan="3"><input id="orders"
					class="inputxt" name="orders" value="${orders}" datatype="num">
					<span class="Validform_checktip">填写显示顺序</span></td>
			</tr>

		</table>
	</t:formvalid>

</body>